package com.ruoyi.web.controller.complain;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.system.domain.complain.Complain;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.system.service.IComplainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 投诉受理管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/system/complain")
public class ComplainController extends BaseController
{
    @Autowired
    private IComplainService complainService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        List<Complain> complainList = util.importExcel(file.getInputStream());
        for (int i = 0; i < complainList.size(); i++) {
            Complain complain = complainList.get(i);
            complain.setcTitle("上课睡觉.");
            complainService.insertComplain(complain);
        }
        return AjaxResult.success();
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
        return util.importTemplateExcel("用户数据");
    }


    /**
     * 查询投诉受理管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:complain:list')")
    @GetMapping("/list")
    public TableDataInfo list(Complain complain)
    {
        startPage();
        List<Complain> list = complainService.selectComplainList(complain);
        return getDataTable(list);
    }


    /**
     * 查询投诉受理管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:complain:list2')")
    @GetMapping("/list2")
    public TableDataInfo list2(Complain complain)
    {
        System.out.println(".........................................................................................................");
        startPage();
        List<Complain> list = complainService.selectComplainList2(complain);
        return getDataTable(list);
    }

    /**
     * 导出投诉受理管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:complain:export')")
    @Log(title = "投诉受理管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Complain complain)
    {
        List<Complain> list = complainService.selectComplainList(complain);
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        util.exportExcel(response, list, "投诉受理管理数据");
    }

    /**
     * 获取投诉受理管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:complain:query')")
    @GetMapping(value = "/{complaintId}")
    public AjaxResult getInfo(@PathVariable("complaintId") Integer complaintId)
    {
        return success(complainService.selectComplainByComplaintId(complaintId));
    }

    /**
     * 新增投诉受理管理
     */
    @PreAuthorize("@ss.hasPermi('system:complain:add')")
    @Log(title = "投诉受理管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complain complain)
    {

        return toAjax(complainService.insertComplain(complain));
    }

    /**
     * 修改投诉受理管理
     */
    @PreAuthorize("@ss.hasPermi('system:complain:edit')")
    @Log(title = "投诉受理管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complain complain)
    {
        return toAjax(complainService.updateComplain(complain));
    }

    /**
     * 删除投诉受理管理
     */
    @PreAuthorize("@ss.hasPermi('system:complain:remove')")
    @Log(title = "投诉受理管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complaintIds}")
    public AjaxResult remove(@PathVariable Integer[] complaintIds) {
        if ( complainService.deleteComplainByComplaintIds(complaintIds)==1)
        return success();
        else
        return error("您选中了未处理的受理请求 请处理在删除o~~~~");
    }



//    @PreAuthorize("@ss.hasPermi('system:complain:delComplain2')")
//    @Log(title = "投诉受理管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{complaintIds}")
//    public AjaxResult complaintIds(@PathVariable Integer[] complaintIds) {
//        if ( complainService.deleteComplainByComplaintIds(complaintIds)==1)
//            return success();
//        else
//            return error("您选中了未处理的受理请求 请处理在删除o~~~~");
//    }
}
